package com.small.account.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.small.account.entity.AuRole;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**

 * 角色 Mapper 接口

 *
 * @author wangguochao
 * @since 2020-01-06
 */
public interface AuRoleMapper extends BaseMapper<AuRole> {
    /**
     * 用户角色
     */
    @Select(" SELECT _ar.*,_uar.user_id FROM au_role _ar JOIN user_and_role _uar ON _ar.id = _uar.role_id JOIN au_user _au ON _au.id = _uar.user_id WHERE _au.id = #{userId}")
    List<AuRole> getUserRole(String userId);

    @Select(" SELECT count(*) FROM au_role _ar JOIN user_and_role _uar ON _ar.id = _uar.role_id JOIN au_user _au ON _au.id = _uar.user_id WHERE _ar.id = #{roleId}")
    int getUserRoleCount(String roleId);

}
